;(function($) {
    $.fn.extend({
        "app_widgets_Droplist": function(options) {
            var options=$.extend({
                oEvent:"click",
                element:"#J_header_typename",
                dropEle:"#J_header_droplist",
                offsetX:-1,
                offsetY:1,
                dropChild:"li",
                defaultID:0,
                callback: function() {
                }
            },options|| {});
            return this.each( function() {
                var _elePos= {};
                var _oldText=$(options.element).text();
                var _tempInterval;
                var _onceFlag=true;
                var $_DropList=$(options.dropEle).find(options.dropChild);
                var $_DropLink=$_DropList.find("a");
                //单例方法
                _elePos.h=$(options.element).outerHeight();
                $(options.dropEle).find("a:last").addClass("no_border");
                var _formElement= {
                    getPos: function() {
                        _elePos.l=$(options.element).offset().left;
                        _elePos.t=$(options.element).offset().top;
                        return _elePos;
                    },
                    setPos: function() {
                        var _elePos=_formElement.getPos();
                        $(options.dropEle).show().css({
                            "left":_elePos.l+options.offsetX,
                            "top":_elePos.t+_elePos.h+options.offsetY
                        });
                    }
                };
                //event list
                $(options.element).bind(options.oEvent, function(e) {
                    _formElement.setPos();
                    return false;
                })
                $(options.dropEle).find("a").live("click", function(index) {
                    //第一次初始化设置
                    var _index=$(options.dropEle).find("a").index($(this)[0]);
                    _oldText=$(options.element).text();
                    var _typeRel=$(this).attr("rel");
                    var _menuText=$(this).text();
                    $(options.element).html(_menuText).attr("rel",_typeRel);
                    $(options.dropEle).find("a").removeClass("no_border");
                    $(options.dropEle).find("a:last").addClass("no_border");
                    $_DropList.show();
                    //$(this).parent().hide();
                    $(options.dropEle).hide();
                    //feedback callback
                    if(typeof(options.callback)=='function'&&(options.callback).constructor==Function) {
                        options.callback();
                    }
                });
                //触发一下
                if(options.defaultID!=null) {
                    $(options.dropEle).find("a").eq(options.defaultID).trigger("click");
                }
                $(options.dropEle).mouseout( function() {
                    _tempInterval=setTimeout( function() {
                        $(options.dropEle).hide();
                    },100);
                }).mouseover( function() {
                    window.clearTimeout(_tempInterval);
                });
            });
        }
    });
})(jQuery);